package com.itheima.reggie.common;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice//异常通知类
@Component
public class CommonExceptionResolver {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R handlerException(SQLIntegrityConstraintViolationException e){
        e.printStackTrace();
        //账号存在
        String message = e.getMessage();
        String[] split = message.split("'");
        return R.error(split[1]+"存在!!");
    }
}
